import { createSlice } from "@reduxjs/toolkit"  
import axios from "axios";
//创建切片对象
let lolSlice = createSlice({
    name:"lol",
    initialState:{
        value:[]
    },
    reducers:{
        saveLol(state,{payload}){
            state.value = payload;
        }
    }
})

// 提取 action 方法
let {saveLol} = lolSlice.actions;

//创建异步方法 请求lol数据
export let asyncGetLol = ()=>{
    return async (dispatch)=>{
        //请求数据
        let {data}  = await axios.get("http://api.xiaohigh.com/lol");
        // console.log(data);

        let lol = data.slice(0,73)
        //调用同步方法更新 store 数据
        dispatch(saveLol(lol));
    }
}

//暴露 reduce 函数
export default lolSlice.reducer;